FILE *f;
guchar buffer [128];
GdkPixbufModule *image_module;
+ gchar *utf8_filename;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
f = fopen (filename, "rb");
if (!f) {
+ utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
_("Failed to open file '%s': %s"),
- filename, g_strerror (errno));
+ utf8_filename ? utf8_filename : "???",
+ g_strerror (errno));
+ g_free (utf8_filename);
return NULL;
}
size = fread (&buffer, 1, sizeof (buffer), f);
if (size == 0) {
+ utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image file '%s' contains no data"),
- filename);
+ utf8_filename ? utf8_filename : "???");
+ g_free (utf8_filename);
fclose (f);
return NULL;
g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
image_module->module_name);
+ utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Failed to load image '%s': reason not known, probably a corrupt image file"),
- filename);
+ utf8_filename ? utf8_filename : "???");
+ g_free (utf8_filename);
}
if (pixbuf == NULL)
g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
image_module->module_name);
+ utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Failed to load animation '%s': reason not known, probably a corrupt animation file"),
- filename);
+ utf8_filename ? utf8_filename : "???");
+ g_free (utf8_filename);
}
fclose (f);
gint score, best = 0;
GdkPixbufModule *selected = NULL;
+ gchar *utf8_filename = NULL;
+
for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) {
GdkPixbufModule *module = (GdkPixbufModule *)modules->data;
score = format_check (module, buffer, size);
return selected;
if (filename)
- g_set_error (error,
- GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
- _("Couldn't recognize the image file format for file '%s'"),
- filename);
+ utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
+
+ if (utf8_filename) {
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
+ _("Couldn't recognize the image file format for file '%s'"),
+ utf8_filename);
+ g_free (utf8_filename);
+ }
else
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
_("Unrecognized image file format"));
-
+
return NULL;
}
f = fopen (filename, "rb");
if (!f) {
+ gchar *utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
_("Failed to open file '%s': %s"),
- filename, g_strerror (errno));
+ utf8_filename ? utf8_filename : "???",
+ g_strerror (errno));
+ g_free (utf8_filename);
return NULL;
}
size = fread (&buffer, 1, sizeof (buffer), f);
if (size == 0) {
+ gchar *utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image file '%s' contains no data"),
- filename);
-
+ utf8_filename ? utf8_filename : "???");
+ g_free (utf8_filename);
fclose (f);
return NULL;
}
fclose (f);
if (pixbuf == NULL && error != NULL && *error == NULL) {
+
/* I don't trust these crufty longjmp()'ing image libs
* to maintain proper error invariants, and I don't
* want user code to segfault as a result. We need to maintain
- * the invariastable/gdk-pixbuf/nt that error gets set if NULL is returned.
+ * the invariant that error gets set if NULL is returned.
*/
-
+
+ gchar *utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
+
g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.", image_module->module_name);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Failed to load image '%s': reason not known, probably a corrupt image file"),
- filename);
-
+ utf8_filename ? utf8_filename : "???");
+ g_free (utf8_filename);
} else if (error != NULL && *error != NULL) {
/* Add the filename to the error message */
GError *e = *error;
- gchar *old;
-
+ gchar *old;
+ gchar *utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
+
old = e->message;
e->message = g_strdup_printf (_("Failed to load image '%s': %s"),
- filename, old);
+ utf8_filename ? utf8_filename : "???",
+ old);
+ g_free (utf8_filename);
g_free (old);
}
-
+
return pixbuf;
}
f = fopen (filename, "rb");
if (!f) {
+ gchar *utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
_("Failed to open file '%s': %s"),
- filename, g_strerror (errno));
+ utf8_filename ? utf8_filename : "???",
+ g_strerror (errno));
+ g_free (utf8_filename);
return NULL;
}
info.width = width;
info.height = height;
-
+
g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
while (!feof (f) && !ferror (f)) {
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (!pixbuf) {
+ gchar *utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
+
g_object_unref (loader);
- g_set_error (error,
+
+ g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Failed to load image '%s': reason not known, probably a corrupt image file"),
- filename);
+ utf8_filename ? utf8_filename : "???");
+ g_free (utf8_filename);
return NULL;
}
f = fopen (filename, "wb");
if (f == NULL) {
+ gchar *utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
_("Failed to open '%s' for writing: %s"),
- filename, g_strerror (errno));
+ utf8_filename ? utf8_filename : "???",
+ g_strerror (errno));
+ g_free (utf8_filename);
return FALSE;
}
}
if (fclose (f) < 0) {
+ gchar *utf8_filename = g_filename_to_utf8 (filename, -1,
+ NULL, NULL, NULL);
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
_("Failed to close '%s' while writing image, all data may not have been saved: %s"),
- filename, g_strerror (errno));
+ utf8_filename ? utf8_filename : "???",
+ g_strerror (errno));
+ g_free (utf8_filename);
return FALSE;
}